package cz.vutbr.fit.xzemko01.tfmcbs.validation.validators;

import java.util.Map;

import org.eclipse.emf.common.util.DiagnosticChain;

import cz.vutbr.fit.xzemko01.tfmcbs.model.Port;
import cz.vutbr.fit.xzemko01.tfmcbs.model.Provider;
import cz.vutbr.fit.xzemko01.tfmcbs.model.ProvidingPort;

public class ProvidingPortValidator implements Validator<ProvidingPort> {
	
	private static ProvidingPortValidator requiringPortValidator;
	
	private Validator<Port> portValidator;
	private Validator<Provider> providerValidator;
	
	private ProvidingPortValidator() {
		portValidator = PortValidator.getInstance();
		providerValidator = ProviderValidator.getInstance();
	}
	
	public static Validator<ProvidingPort> getInstance() {
		if(requiringPortValidator == null) {
			requiringPortValidator = new ProvidingPortValidator();
		}
		return requiringPortValidator;
	}
	
	@Override
	public boolean validate(ProvidingPort port, DiagnosticChain diagnostics, Map<Object, Object> context) {
		boolean result = portValidator.validate(port, diagnostics, context);
		result &= providerValidator.validate(port, diagnostics, context);
		
		return result;
	}
}
